package com.repair.system.repository;

import com.repair.system.entity.FaultRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface FaultRecordRepository extends JpaRepository<FaultRecord, Long> {
    List<FaultRecord> findByStatusOrderByCreatedAtDesc(FaultRecord.FaultStatus status);
    
    List<FaultRecord> findByDeviceNameContainingIgnoreCase(String deviceName);
    
    @Query("SELECT f FROM FaultRecord f WHERE f.occurrenceTime BETWEEN :startDate AND :endDate")
    List<FaultRecord> findByDateRange(LocalDateTime startDate, LocalDateTime endDate);
    
    long countByStatus(FaultRecord.FaultStatus status);
    
    List<FaultRecord> findTop10ByOrderByCreatedAtDesc();
}
